package 一些笔试真题;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-10-04
 * Time: 23:19
 */

/*
    计算复数乘法
 */
public class bilibili_1 {
    public static int stringToInt(String s){
        int num = 0;
        int flag = 1;
        int len = s.length();
        for(int i = 0; i < len; i++){
            if(s.charAt(i) == '-'){
                flag = -1;
            }else if(s.charAt(i) >= '0' && s.charAt(i) <= '9'){
                num = num * 10 + (s.charAt(i) - '0');
            }
        }
        return num * flag;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        String s2 = scanner.next();
        //截取整数部分
        String s1First = s1.substring(0, s1.indexOf('+'));
        String s2First = s2.substring(0, s2.indexOf('+'));
        //截取复数部分
        String s1Second = s1.substring(s1.indexOf('+') + 1);
        String s2Second = s2.substring(s2.indexOf('+') + 1);
        //按照指定规则将字符串转成整数
        int s1F = stringToInt(s1First);
        int s2F = stringToInt(s2First);
        int s1S = stringToInt(s1Second);
        int s2S = stringToInt(s2Second);
        //计算出结果的整数和复数部分
        int F = s1F * s2F - s1S * s2S;
        int S = s1F * s2S + s1S * s2F;
        System.out.println(F + "+" + S + "i");
    }
}
